package com.kim.smartring.adapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.kim.smartring.R;
import com.kim.smartring.db.model.HeartRateRecord;
import com.kim.smartring.db.model.SleepRecord;

public class SummaryDataAdapter extends PagerAdapter {

	private LayoutInflater inflater;

	static List<View> views = null;

	private HashMap<String, HeartRateRecord> heartRates = null;
	private HashMap<String, SleepRecord> sleeps = null;

	public SummaryDataAdapter(Context context,
			HashMap<String, HeartRateRecord> heartRates,
			HashMap<String, SleepRecord> sleeps) {
		inflater = LayoutInflater.from(context);
		refreshData(heartRates, sleeps);

		if (views == null) {
			views = new ArrayList<View>(3);

			View v = inflater.inflate(R.layout.summery_data_item, null);
			views.add(v);
			v = inflater.inflate(R.layout.summery_data_item, null);
			views.add(v);
			v = inflater.inflate(R.layout.summery_data_item, null);
			views.add(v);
		}
	}

	public void refreshData(HashMap<String, HeartRateRecord> heartRates,
			HashMap<String, SleepRecord> sleeps) {
		this.heartRates = heartRates;
		this.sleeps = sleeps;
	}

	@Override
	public int getCount() {

		return views.size();
		// return heartRates.size() > sleeps.size() ? heartRates.size() : sleeps
		// .size();
	}

	@Override
	public boolean isViewFromObject(View view, Object obj) {
		return view == obj;
	}

	@Override
	public Object instantiateItem(ViewGroup container, int position) {
		// View contentViewItem = inflater.inflate(R.layout.summery_data_item,
		// container, false);
		// return contentViewItem; // super.instantiateItem(container,
		// position);
		View v = inflater.inflate(R.layout.summery_data_item, null);
		container.addView(v);
		return v;
	}

	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		container.removeView((View) object);
		// super.destroyItem(container, position, object);
	}

}
